package com.igeekhome.service.impl;

import com.igeekhome.mapper.DNetworkMapper;
import com.igeekhome.mapper.SysStaffMapper;
import com.igeekhome.pojo.DNetwork;
import com.igeekhome.pojo.SysStaff;
import com.igeekhome.pojo.SysStaffExample;
import com.igeekhome.service.ILoginService;
import com.igeekhome.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Romeo
 */
@Service("loginService")
public class LoginServiceImpl implements ILoginService {

    @Autowired
    private SysStaffMapper sysStaffMapper;
    @Autowired
    private DNetworkMapper dNetworkMapper;
    /**
     *  判断账号密码时候正确，如果正确则SysStaff有值，反之则为空
     */

    @Override
    public SysStaff loginStaff(Integer loginAccount, String password) {
        // 先对密码进行加密操作，在进行比较
        String passwordMd5 = CommonUtil.md5(password);
        SysStaffExample example = new SysStaffExample();
        example.createCriteria().andLoginAccountEqualTo(loginAccount).andLoginPasswordEqualTo(passwordMd5);
        List<SysStaff> sysStaff = sysStaffMapper.selectByExample(example);
        if(sysStaff != null && sysStaff.size() > 0){
            return sysStaff.get(0);
        }
        return null;
    }

    /**
     * 查询登录账户所在网点，可以复用网点的查询语句，后期可以修改
     */
    @Override
    public DNetwork getNetwork(Integer networkId) {
        DNetwork dNetwork = dNetworkMapper.selectByPrimaryKey(networkId);
        return dNetwork;
    }
}
